import Airspace from '/public/airspace/airspace.json'
export function overviewInit() {
  __g.camera.set(524554.446582, 2494827.02749, 80.719521, 0.748561, -144.686874, 0)
  // addAirSpace()
  // addmarker3d()
}

const colors = ['#00e24f', '#00a7eb', '#00e24f', '#00e24f', '#00e24f', '#00e24f', '#00e24f']
//添加七大空域
async function addAirSpace() {
  const polygonArr = []
  Airspace.forEach((item, index) => {
    const opolygon = {
      id: 'airspace-' + index, //3DPolygon唯一标识id
      groupId: 'airspace',
      coordinates: item.geometry.coordinates[0], //构成3DPolygon的坐标点数组
      color: colors[index], //3DPolygon颜色
      height: 1000, //3D多边形的高度
      intensity: 1.0, //亮度
      style: 1, //3DPolygon的样式 请参照API开发文档选取枚举
      generateTop: true, //是否生成顶面
      generateSide: true, //是否生成侧面
      generateBottom: true //是否生成底面
    }
    polygonArr.push(opolygon)
  })
  //批量添加3DPolygon
  await __g.polygon3d.add(polygonArr)
}

const markers = [
  {
    name: '大小梅沙片区',
    coordinate: [532613.33, 2500076.48, 1000]
  },
  {
    name: '盐田港马峦山',
    coordinate: [528222.64, 2496993.6, 1000]
  },
  {
    name: '东部华侨城片区',
    coordinate: [527536.9400000001, 2502249.7600000002, 1000]
  },
  {
    name: '保惠冷链物流园片区',
    coordinate: [525482.86, 2499031.68, 1000]
  },
  {
    name: '区政府南边中央公园',
    coordinate: [524281.74, 2495788.96, 1000]
  },
  {
    name: '恩上公园片区',
    coordinate: [523785.9225, 2497277.92, 1000]
  },
  {
    name: '正坑水库片区',
    coordinate: [522087.8125, 2495794.24, 1000]
  }
]
async function addmarker3d() {
  const marker3dArr = []
  const BPFunctions = []
  markers.forEach((item, index) => {
    let o = {
      id: 'airspace-' + index,
      groupId: 'airspace',
      textVisible: false, //3D标注显示文字是否显示文本
      pointName: '3D_UI_B_1', //3D标注展示的特效名称
      pointVisible: true, //3D标注是否显示
      pointScale: index < 2 ? 300 : 150, //3D标注整体缩放比例
      coordinate: item.coordinate, //3D标注的坐标位置 注意：若坐标Z设置高度为0时 autoHeight=true则会显示在物体上方
      coordinateType: 0, //坐标系类型
      range: [1, 100000], //3D标注的可视距离范围：[min,max]，单位：米
      autoHeight: false, //自动判断下方是否有物体，设置正确高度，默认值：false
      userData: item.name
    }
    marker3dArr.push(o)

    BPFunctions.push({
      id: 'airspace-' + index,
      functionName: '文字',
      parameters: [
        {
          paramType: 5,
          paramValue: item.name
        },
        {
          paramType: 2,
          paramValue: 48
        },
        {
          paramType: 6,
          paramValue: [1, 1, 1, 1]
        }
      ]
    })
  })
  await __g.marker3d.add(marker3dArr)
  await __g.marker3d.callBPFunction(BPFunctions)
}

export function overviewClear() {
  __g.marker3d.clear(null)
  __g.marker.clear(null)
  __g.polyline.clear(null)
  __g.polygon3d.clear(null)
}
